package fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.a513.R;

public class LaunchFragment extends Fragment {
    public static LaunchFragment newInstance(int count,int position,int img_id) {

        Bundle args = new Bundle();
        args.putInt("count",count);
        args.putInt("position",position);
        args.putInt("img_id",img_id);
        LaunchFragment fragment = new LaunchFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Bundle arguments = getArguments();
        int position = arguments.getInt("position");
        int pic = arguments.getInt("img_id");
        int count = arguments.getInt("count");

        View view = LayoutInflater.from(getContext()).inflate(R.layout.item_launch,container,false);
        ImageView imageView = view.findViewById(R.id.iv_launcher);
        RadioGroup rg_group = view.findViewById(R.id.radio_group);
        imageView.setImageResource(pic);

        for (int i = 0; i < count; i++){
            RadioButton radioButton = new RadioButton(getContext());
            radioButton.setLayoutParams(new ViewGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT));
            radioButton.setPadding(40,40,40,40);
            rg_group.addView(radioButton);
        }
        ((RadioButton) rg_group.getChildAt(position)).setChecked(true);

        if (position == count -1 ){

        }
        return view;
    }
}
